use crate::http::server::error::Error;
use crate::http::server::handler::result::IntoJsonResponseResult;
use crate::http::server::middleware::ValidatedJson;
use crate::{controller, dto};
use axum::Json;
use axum::extract::State;
use std::sync::Arc;

pub struct EndpointSrv6ConfigHandler {
    controller_set: Arc<controller::ControllerSet>,
}

impl EndpointSrv6ConfigHandler {
    pub fn new(controller_set: Arc<controller::ControllerSet>) -> Self {
        Self { controller_set }
    }
}

impl EndpointSrv6ConfigHandler {
    pub async fn get(
        State(state): State<Arc<Self>>,
        request: ValidatedJson<dto::endpoint_srv6_config::GetRequest>,
    ) -> Result<
        Json<wanmesh_common::dto::Response<dto::core::endpoint_srv6_config::EndpointSrv6Config>>,
        Error,
    > {
        state
            .controller_set
            .endpoint_srv6_config
            .get(&request.0)
            .await
            .into_json_response_result()
    }

    pub async fn update(
        State(state): State<Arc<Self>>,
        request: ValidatedJson<dto::endpoint_srv6_config::UpdateRequest>,
    ) -> Result<Json<wanmesh_common::dto::Response<()>>, Error> {
        state
            .controller_set
            .endpoint_srv6_config
            .update(&request.0)
            .await
            .into_json_response_result()
    }
}
